// pages/teacher/revenue/revenue.js
Page({
  data: {
    currentTab: 0,
    tabs: ['收益概览', '收益明细', '提现记录'],
    // 收益概览
    overview: {
      totalRevenue: 45680.50,
      availableBalance: 12350.00,
      withdrawing: 3200.00,
      withdrawed: 30130.50
    },
    // 本月收益趋势
    monthlyTrend: [
      { date: '10-01', amount: 580 },
      { date: '10-05', amount: 1200 },
      { date: '10-10', amount: 890 },
      { date: '10-15', amount: 1560 },
      { date: '10-20', amount: 2100 },
      { date: '10-25', amount: 1780 }
    ],
    // 收益明细
    revenueList: [
      {
        id: 1,
        type: 'course_sale',
        title: '课程销售：微信小程序开发实战',
        amount: 199.00,
        studentName: '张同学',
        createTime: '2025-10-28 10:30',
        status: 'available'
      },
      {
        id: 2,
        type: 'course_sale',
        title: '课程销售：Python数据分析与挖掘',
        amount: 249.00,
        studentName: '李同学',
        createTime: '2025-10-27 15:20',
        status: 'available'
      },
      {
        id: 3,
        type: 'course_sale',
        title: '课程销售：UI/UX设计精品课',
        amount: 299.00,
        studentName: '王同学',
        createTime: '2025-10-26 20:15',
        status: 'pending'
      }
    ],
    // 提现记录
    withdrawList: [
      {
        id: 1,
        amount: 5000.00,
        status: 'success',
        applyTime: '2025-10-20 10:00',
        completeTime: '2025-10-22 14:30',
        account: '尾号1234'
      },
      {
        id: 2,
        amount: 3200.00,
        status: 'pending',
        applyTime: '2025-10-26 16:00',
        account: '尾号1234'
      }
    ],
    // 可提现余额
    canWithdraw: 12350.00,
    minWithdraw: 100.00
  },
  onLoad() {},
  switchTab(e) {
    this.setData({
      currentTab: e.currentTarget.dataset.index
    })
  },
  applyWithdraw() {
    const { canWithdraw, minWithdraw } = this.data
    if (canWithdraw < minWithdraw) {
      wx.showToast({
        title: `最低提现金额¥${minWithdraw}`,
        icon: 'none'
      })
      return
    }
    wx.showModal({
      title: '申请提现',
      content: `确认提现¥${canWithdraw}到绑定账户？`,
      success: (res) => {
        if (res.confirm) {
          wx.showLoading({ title: '提交中...' })
          setTimeout(() => {
            wx.hideLoading()
            wx.showToast({
              title: '提现申请已提交',
              icon: 'success'
            })
          }, 1500)
        }
      }
    })
  },
  viewRevenueDetail(e) {
    const id = e.currentTarget.dataset.id
    wx.showToast({
      title: '查看收益详情',
      icon: 'none'
    })
  },
  exportRevenue() {
    wx.showLoading({ title: '导出中...' })
    setTimeout(() => {
      wx.hideLoading()
      wx.showToast({
        title: '导出成功',
        icon: 'success'
      })
    }, 1500)
  }
})
